//
//  ProgressHUDManage.m
//  EduOnLine
//
//  Created by Mac on 2019/11/14.
//  Copyright © 2019 eduonline. All rights reserved.
//

#import "ProgressHUDManage.h"
#import "UIImage+GIF.h"

@interface ProgressHUDManage()

@property (nonatomic ,strong) MBProgressHUD *myHud;

@end


@implementation ProgressHUDManage


+ (instancetype)shareObject{
    
    static ProgressHUDManage *progressHUDManage = nil;
    static dispatch_once_t oncetoken;
    dispatch_once(&oncetoken, ^{
        progressHUDManage = [[ProgressHUDManage alloc] init];
        progressHUDManage.showErrorTips = YES;
        progressHUDManage.showLoadingTips = YES;
        [progressHUDManage setWBOCRConfig];
    });
    
    return progressHUDManage;
}


- (void)setWBOCRConfig{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setBackgroundColor:kColorRGBA(0, 0, 0, 0.5)];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [SVProgressHUD setErrorImage:[UIImage imageNamed:@""]];
    [SVProgressHUD setMinimumDismissTimeInterval:2];
    [SVProgressHUD setMaximumDismissTimeInterval:80];
    [SVProgressHUD setImageViewSize:CGSizeMake(60, 60)];
//    NSString  *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:@"loding@2x.gif" ofType:nil];
//    NSData  *imageData = [NSData dataWithContentsOfFile:filePath];
//    [SVProgressHUD setInfoImage:[UIImage sd_animatedGIFWithData:imageData]];
}



//显示成功提示
+ (void)showSuccess:(NSString *)success
{
    
    [[ProgressHUDManage shareObject].myHud hideAnimated:NO];
    [ProgressHUDManage shareObject].myHud = [MBProgressHUD showSuccess:success];
    
//    [ProgressHUDManage shareObject].myHud.label.text = success;
//    [ProgressHUDManage shareObject].myHud.label.numberOfLines = 0;
//    [ProgressHUDManage shareObject].myHud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", @"success"]]];
//    [ProgressHUDManage shareObject].myHud.mode = MBProgressHUDModeCustomView;
//    [[ProgressHUDManage shareObject].myHud hideAnimated:YES afterDelay:1.5];
    
}

//显示失败提示
+ (void)showError:(NSString *)error
{
    [[ProgressHUDManage shareObject].myHud hideAnimated:NO];
    [ProgressHUDManage shareObject].myHud = [MBProgressHUD showError:error];
//    [ProgressHUDManage shareObject].myHud.label.text = error;
//    [ProgressHUDManage shareObject].myHud.label.numberOfLines = 0;
//    [ProgressHUDManage shareObject].myHud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", @"error"]]];
//    [ProgressHUDManage shareObject].myHud.mode = MBProgressHUDModeCustomView;
//    [[ProgressHUDManage shareObject].myHud hideAnimated:YES afterDelay:1.5];
}

//显示提醒信息
+ (void)showInfo:(NSString *)info
{
    [[ProgressHUDManage shareObject].myHud hideAnimated:NO];
    [ProgressHUDManage shareObject].myHud = [MBProgressHUD showInfo:info];
}

//在底部显示文本
+ (void)showText:(NSString *)text
{
    [MBProgressHUD showtext:text];
//    [[ProgressHUDManage shareObject].myHud hideAnimated:NO];
//    [ProgressHUDManage shareObject].myHud = [MBProgressHUD showtext:text];
}


//显示加载提示
+ (void)showLoading:(NSString *)text
{
    if ([ProgressHUDManage shareObject].myHud.mode == MBProgressHUDModeIndeterminate) {
        if ([ProgressHUDManage shareObject].myHud.superview == nil) {
            [[UIApplication sharedApplication].keyWindow addSubview:[ProgressHUDManage shareObject].myHud];
        }
        [ProgressHUDManage shareObject].myHud.label.text = text;
        [[ProgressHUDManage shareObject].myHud showAnimated:YES];
       
    }else{
         [[ProgressHUDManage shareObject].myHud hideAnimated:NO];
        [ProgressHUDManage shareObject].myHud = nil;
         [ProgressHUDManage shareObject].myHud.label.text = text;
         [ProgressHUDManage shareObject].myHud.mode = MBProgressHUDModeIndeterminate;
         [[ProgressHUDManage shareObject].myHud showAnimated:YES];
    }
    
}

+ (void)hideTips
{
    [QMUITips hideAllTips];
    [[ProgressHUDManage shareObject].myHud hideAnimated:NO];
}


-(MBProgressHUD *)myHud
{
    if (!_myHud) {
        
        _myHud = [MBProgressHUD showHUDAddedTo:kAppWindow animated:YES];
        //放置图片和文字的view,设置了蒙版就使用不了背景颜色
        //    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
            //不使用蒙版,使用背景颜色
        [ProgressHUDManage shareObject].myHud.label.text = @"";
        [ProgressHUDManage shareObject].myHud.mode = MBProgressHUDModeIndeterminate;
        _myHud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        _myHud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
        //图片和文字的颜色
        _myHud.contentColor = [UIColor whiteColor];
        _myHud.removeFromSuperViewOnHide = NO;
    }
    return _myHud;
}







@end
